From: Robert Lipe Date: Tue, 22 Sep 2015 01:56:41 +0000 (-0500) Subject: Hack up GPX writer to prepare for GGZ. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~10^2~16^2~2 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=e529697c7247b0df99c94e05c73045efb2ed5999;p=gpsbabel.git Hack up GPX writer to prepare for GGZ. optionally split output in gpx writer. Keep a list of files we’ve created so that GGZ writer can turn around and read them. --- diff --git a/gpx.cc b/gpx.cc index 4778b83a4..7e2560d1c 100644 --- a/gpx.cc +++ b/gpx.cc @@ -23,10 +23,12 @@ #include "cet_util.h" #include "garmin_fs.h" #include "garmin_tables.h" +#include "gpx.h" #include "src/core/logging.h" #include "src/core/file.h" #include "src/core/xmlstreamwriter.h" #include "src/core/xmltag.h" +#include "src/core/ziparchive.h" #include #include @@ -62,9 +64,12 @@ static short_handle mkshort_handle; static QString link_url; static QString link_text; static QString link_type; +static QString output_file_name; +static QList gpx_files_written_; static char* snlen = NULL; +static char* split = NULL; static char* suppresswhite = NULL; static char* urlbase = NULL; static route_head* trk_head; @@ -1227,9 +1232,33 @@ gpx_rd_deinit(void) cur_tag = NULL; } +// Secret accessor to return an array of file names that we have written. +QList GetGpxFilesWritten() { + return gpx_files_written_; +} + +// When we're writing multiple GPX files, get the output filename (which may +// have a path component) in the current sequence. +static QString GetOutFname(int seq) { + static const char* kNameToken = "__NUM__"; + + QString sequence = QString("%1").arg(seq); + QString s = output_file_name; + s.replace(kNameToken, sequence); + return s; +} + static void -gpx_wr_init(const char* fname) +gpx_wr_init(const char* ifname) { + QString fname = ifname; + if (output_file_name.isEmpty()) { + output_file_name = fname; + // Our first name is "one". + fname = GetOutFname(1); + } + gpx_files_written_.append(fname); + mkshort_handle = NULL; oqfile = new gpsbabel::File(fname); oqfile->open(QIODevice::WriteOnly | QIODevice::Text); @@ -1655,6 +1684,17 @@ gpx_waypt_pr(const Waypoint* waypointp) fs_xml* fs_gpx; garmin_fs_t* gmsd; /* gARmIN sPECIAL dATA */ + // If we're splitting files and the output buffer is approaching + // our split we close the file we were last writing and open a new + // one. + static const double kSplitPercent = 0.99; + if (oqfile->size() > atoi(split) * kSplitPercent) { + static int x = 2; // The first one is "one" automatically. + gpx_wr_deinit(); + QString fn = GetOutFname(x++); + gpx_wr_init(CSTR(fn)); + } + writer->writeStartElement("wpt"); writer->writeAttribute("lat", toString(waypointp->latitude)); writer->writeAttribute("lon", toString(waypointp->longitude)); @@ -1929,6 +1969,10 @@ arglist_t gpx_args[] = { "snlen", &snlen, "Length of generated shortnames", "32", ARGTYPE_INT, "1", NULL, NULL }, + { + "split", &split, "split wpts after this many bytes ", + "500000", ARGTYPE_INT, "1", NULL, NULL + }, { "suppresswhite", &suppresswhite, "No whitespace in generated shortnames", diff --git a/gpx.h b/gpx.h new file mode 100644 index 000000000..f61cef875 --- /dev/null +++ b/gpx.h @@ -0,0 +1,21 @@ +/* + Access GPX data files. + + Copyright (C) 2002-2015 Robert Lipe, gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ +QList GetGpxFilesWritten();